/**
  ****************************************************************************************************
  * @file    main.c
  * @author  FMSH Application Team
  * @brief   Header file of FL Module
  ****************************************************************************************************
  * @attention

  ****************************************************************************************************
  */
#define _MAIN_C_
/* Includes ---------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "main.h"

/* USER CODE END Includes */

/* Types ------------------------------------------------------------*/
/* USER CODE BEGIN Types */

/* USER CODE END Types */

/* Constants --------------------------------------------------------*/
/* USER CODE BEGIN Constants */

/* USER CODE END Constants */

/* Macro ------------------------------------------------------------*/
/* USER CODE BEGIN Macro */

/* USER CODE END Macro */

/* Variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
uint16_t guiSysFlag = 0;
/* USER CODE END Variables */

/* Function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FP */
void IWDT_Init(void);
void SysClockInit(void);
void SysConfigInit(void);
/* USER CODE END FP */

int main(void)
{
    /* Initialize FL Driver Library */
    FL_Init();
    /* Configure the system clock */
    SysClockInit();
    /* Initialize all configured peripherals */
    SysConfigInit();
	/* Power on load system data */
	//vDataFlashPowerOnLoadData();
	
    for(;;)
    {
		vUART0MsgHandler();
		
		FL_IWDT_ReloadCounter(IWDT);
		
		//vRelaySwitchWithHARTOrMeter(eChannel16, eHART, _ON);
		//FL_DelayMs(2000);
		//vRelaySwitchWithHARTOrMeter(eChannel16, eHART, _OFF);
		//FL_DelayMs(2000);
    }
}
/**
  * @brief  None
  * @param  void
  * @retval None
  */
void IWDT_Init(void)
{
    FL_IWDT_InitTypeDef    IWDT_InitStruct;

    IWDT_InitStruct.iwdtWindows = 0;
    IWDT_InitStruct.overflowPeriod = FL_IWDT_PERIOD_8000MS;

    FL_IWDT_Init(IWDT, &IWDT_InitStruct);
}
/**
  * @brief  None
  * @param  void
  * @retval None
  */
void SysClockInit(void)
{
    //FL_GPIO_InitTypeDef GPIO_InitStruct = {0};

    FL_CMU_XTHF_WriteDriverStrength(0x0A);
    FL_CMU_XTHF_Enable();
    FL_DelayMs(2);
    /* Initial RCHF */
    FL_CMU_RCHF_SetFrequency(FL_CMU_RCHF_FREQUENCY_8MHZ);
    FL_CMU_RCHF_Enable();

    /* Initial System Clock */
    FL_FLASH_SetReadWait(FLASH, FL_FLASH_READ_WAIT_0CYCLE);
    FL_CMU_SetSystemClockSource(FL_CMU_SYSTEM_CLK_SOURCE_XTHF);
    FL_CMU_SetAHBPrescaler(FL_CMU_AHBCLK_PSC_DIV1);
    FL_CMU_SetAPBPrescaler(FL_CMU_APBCLK_PSC_DIV1);

    SystemCoreClockUpdate();
}
/**
  * @brief  None
  * @param  void
  * @retval None
  */
void SysConfigInit(void)
{
	vUART0Init();
	LPTIM32TimerBaseInit();
	LPTIM32Setup();
	vRelayGPIOInit();
	IWDT_Init();
	vDataFlashPowerOnLoadData();
}


